package com.wigem.fa.service;
import java.util.ArrayList;
import java.util.List;
import com.wigem.framework.common.pojo.PageResult;
import com.wigem.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.wigem.fa.entity.FaApplyFileEntity;
import com.wigem.fa.mapper.FaApplyFileMapper;
import com.wigem.fa.vo.FaApplyFileVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;

/**
 * 申请附件Service业务层处理
 *
 * @author ls
 * @date 2024-11-01
 */
@Service
public class FaApplyFileServiceImpl implements FaApplyFileService {

    @Resource
    private FaApplyFileMapper faApplyFileMapper;


    @Override
    public List<FaApplyFileEntity> getList(FaApplyFileVo faApplyFilevo) {

        return faApplyFileMapper.selectList(query(faApplyFilevo));
    }

    @Override
    public PageResult<FaApplyFileEntity> getPageList(FaApplyFileVo faApplyFileVo) {

        return faApplyFileMapper.selectPage(faApplyFileVo, query(faApplyFileVo));
    }


    @Override
    public FaApplyFileEntity getEntity(String id) {
        return faApplyFileMapper.selectById(id);
    }

    @Override
    public List<FaApplyFileEntity> getListByApplyId(String applyId) {
        if(applyId == null){
            return new ArrayList<FaApplyFileEntity>();
        }
        FaApplyFileVo faApplyFileVo=new FaApplyFileVo();
        faApplyFileVo.setApplyId(applyId);
        return faApplyFileMapper.selectList(query(faApplyFileVo));
    }

    @Override
    public void add(FaApplyFileVo faApplyFileVo) { FaApplyFileEntity faApplyFileEntity = new  FaApplyFileEntity();
            BeanUtils.copyProperties(faApplyFileVo, faApplyFileEntity);
            faApplyFileEntity.create();
            faApplyFileMapper.insert(faApplyFileEntity);
    }


    @Override
    public void update(FaApplyFileVo faApplyFileVo) {
            FaApplyFileEntity faApplyFileEntity = new FaApplyFileEntity();
            BeanUtils.copyProperties(faApplyFileVo, faApplyFileEntity);
            faApplyFileMapper.updateById(faApplyFileEntity);
    }

    @Override
    public void save(FaApplyFileVo faApplyFileVo) {

            FaApplyFileEntity faApplyFileEntity = new FaApplyFileEntity();
            BeanUtils.copyProperties(faApplyFileVo,faApplyFileEntity);
                    if (StringUtils.isEmpty(faApplyFileVo.getId())){
            faApplyFileEntity.create();
            faApplyFileMapper.insert(faApplyFileEntity);
            } else {
            faApplyFileMapper.updateById(faApplyFileEntity);
            }

    }

    @Override
    public int deleteAllByApplyId(FaApplyFileEntity faApplyFileentity) {
        return faApplyFileMapper.deleteAllByApplyId(faApplyFileentity);
    }
    @Override
    public int delete(String id) {
        return faApplyFileMapper.deleteById(id);
    }


    @Override
    public int remove(String id) {
        return faApplyFileMapper.remove(id);
    }


    public LambdaQueryWrapperX<FaApplyFileEntity> query(FaApplyFileVo faApplyFileVo) {

        LambdaQueryWrapperX<FaApplyFileEntity>faApplyFileEntityLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
            faApplyFileEntityLambdaQueryWrapperX = faApplyFileEntityLambdaQueryWrapperX
                                                .eqIfPresent(FaApplyFileEntity::getId, faApplyFileVo.getId())
                                                                    .eqIfPresent(FaApplyFileEntity::getApplyId, faApplyFileVo.getApplyId())
                                                                    .eqIfPresent(FaApplyFileEntity::getPolicyType, faApplyFileVo.getPolicyType())
                                                                    .eqIfPresent(FaApplyFileEntity::getFileNo, faApplyFileVo.getFileNo())
                                                                    .eqIfPresent(FaApplyFileEntity::getFileId, faApplyFileVo.getFileId())

;
        return faApplyFileEntityLambdaQueryWrapperX;
    }


}
